package com.wlstock.funi.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wlstock.funi.R;
import com.wlstock.funi.model.OperateModel;
import com.wlstock.funi.utils.CaculateUtils;
import com.wlstock.funi.utils.TimeUtils;

import java.util.ArrayList;

public class TradeAdapter extends BaseAdapter {
	
	private Context mContext;
	private ArrayList<OperateModel> models;
	
	public TradeAdapter(Context mContext){
		super();
		this.mContext = mContext;
	}
	
	public TradeAdapter(Context mContext, ArrayList<OperateModel> operateModels) {
		super();
		this.mContext = mContext;
		this.setModels(operateModels);
	}
	
	public ArrayList<OperateModel> getModels() {
		return models;
	}

	public void setModels(ArrayList<OperateModel> models) {
		this.models = models;
	}
	
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return getModels().size();
	}

	@Override
	public OperateModel getItem(int arg0) {
		// TODO Auto-generated method stub
		return getModels().get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View converView, ViewGroup viewGroup) {
		// TODO Auto-generated method stub
		Holder holder = null;
		if (converView == null) {
			converView = LayoutInflater.from(mContext).inflate(R.layout.list_item_operate_mode, viewGroup, false);
			holder = new Holder();
			holder.personName = (TextView) converView.findViewById(R.id.tv_person_name);
			holder.operatType = (TextView) converView.findViewById(R.id.tv_operate_type);
			holder.stockName  = (TextView) converView.findViewById(R.id.tv_stock_name);
			holder.stockNo    = (TextView) converView.findViewById(R.id.tv_stock_no);
			holder.operatePrice = (TextView) converView.findViewById(R.id.tv_operate_price);
			holder.operateTime = (TextView) converView.findViewById(R.id.tv_operate_time);
			holder.buildTime  = (TextView) converView.findViewById(R.id.tv_build_time);
			holder.update_time =(TextView) converView.findViewById(R.id.tv_update_time);
			holder.sessionProfit =(TextView) converView.findViewById(R.id.tv_session_profit);
			converView.setTag(holder);
		} else {
			holder = (Holder) converView.getTag();
		}
		OperateModel model =  getModels().get(position);
		holder.personName.setText(model.getFundName()+"("+model.getKeepDays(model.getFundid())+")  ");
		holder.operatType.setText(model.getRemark());
		holder.stockName.setText(model.getStockName());
		holder.stockNo.setText(model.getStockNo());
		holder.operatePrice.setText(model.getTradePrice()+"");
		holder.operateTime.setText("操作:"+model.getTradedDay()+" "+TimeUtils.parseHHMM(model.getTradedDate()) );
		holder.buildTime.setText("建立:"+model.getTradedDay()+" "+TimeUtils.parseHHMM(model.getCreatedTime()));
//		holder.update_time.setText("更新时间:"+model.getTradedDay()+" "+TimeUtils.parseHHMM(model.getUpDateTime()));
//		holder.update_time.setText("更新:"+model.getTradedDay()+" "+TimeUtils.parseHHMM(new Date()));
		holder.sessionProfit.setText("本期收益:"+ CaculateUtils.getPercentByFloat(model.getProfitRate()));
		return converView;
	}

	private class Holder{
		
		TextView personName;
		TextView operatType;
		TextView stockName;
		TextView stockNo;
		TextView operatePrice;
		TextView operateConvience;
		TextView operateTime;
		TextView buildTime;
		TextView update_time;
		TextView sessionProfit;
		
	}
	
}
